<?php
/**
 * Created by PhpStorm.
 * User: ADMIN
 * Date: 2021/6/3
 * Time: 6:26
 */
namespace app\adminapi\validate;

use app\common\model\GoodsCategory;

class GoodsCategoryDelete extends Base
{
    protected $rule = [
        'id' => 'require|integer|min:1|dataExists',
    ];

    protected $message = [
        'id.require' => '参数id必须',
        'id.integer' => '参数id只能是数字',
        'id.min' => '参数id最小值为1',
        'id.dataExists' => '删除的数据不存在',
    ];

    /**
     * 分类不存在
     * @param $value
     * @param $rule
     * @param $data
     * @return bool
     * @throws \think\exception\DbException
     */
    protected function dataExists($value, $rule, $data)
    {
        if(!GoodsCategory::get(['id'=>$value])) return false;
        return true;
    }

}